<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="${ctxPath}/assets/expand/images/favicon.ico" rel="icon">
    <title>${constants.getSystemName()}</title>
    <link rel="stylesheet" href="${ctxPath}/assets/common/libs/layui/css/layui.css?v=${constants.getReleaseVersion()}"/>
    <link rel="stylesheet" href="${ctxPath}/assets/common/module/admin.css?v=${constants.getReleaseVersion()}"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <!-- 头部 -->
    @include("/layout/_header.html"){}

    <!-- 侧边栏 -->
    @include("/layout/_sidebar.html"){}

    <!-- 主体部分 -->
    @include("/layout/_body.html"){}

    <!-- 底部 -->
    @include("/layout/_footer.html"){}

</div>

<!-- 加载动画 -->
@include("/layout/loading.html"){}

<!-- js全局变量 -->
<script type="text/javascript">
    var Feng = {
        ctxPath: "${ctxPath}",
        version: '${constants.getReleaseVersion()}',
        wsUrl: '${wsUrl}'
    };
</script>
<script type="text/javascript" src="${ctxPath}/assets/common/libs/layui/layui.js?v=${constants.getReleaseVersion()}"></script>
<script type="text/javascript" src="${ctxPath}/assets/common/js/common.js?v=${constants.getReleaseVersion()}"></script>

<script>
    var wsInst = null
    layui.use(['layer', 'element', 'admin', 'index', 'HttpRequest', 'ws', 'notice', 'i18n'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var admin = layui.admin;
        var index = layui.index;
        var HttpRequest = layui.HttpRequest;
        var ws = layui.ws;
        var notice = layui.notice;
        var i18n = layui.i18n;

        //获取支持的语言列表
        let languageTypes = i18n.getLanguageTypes();
        for (var i = 0; i < languageTypes.length; i++) {
            var code = languageTypes[i].code;
            var description = languageTypes[i].name;
            $("#languageDiv").append('<dd lay-unselect><a id="tran-' + code + '" href="javascript:;">' + description + '</a></dd>');

            //设置监听事件，设置点击按钮切换当前系统语言
            (function (code) {
                $('#tran-' + code).click(function () {
                    i18n.changeUserTranslation(code);
                });
            })(code);
        }

        // 记载并缓存翻译的字典
        i18n.loadAndCacheTranslation();

        // 默认加载主页
        index.loadHome({
            menuPath: $("#firstPageAction").attr('lay-href'),
            menuName: '<i class="layui-icon layui-icon-home"></i>'
        });

        // 修改密码点击事件
        $('#setPsw').click(function () {
            admin.open({
                id: 'pswForm',
                type: 2,
                title: i18n.translate('TITLE_CHANGE_PASSWORD', '修改密码'),
                shade: 0,
                content: '${ctxPath}/view/changePassword'
            });
        });

        // 退出登录点击事件
        $('#btnLogout').click(function () {
            var request = new HttpRequest(Feng.ctxPath + "/logout", 'post', function (data) {
                Feng.success("退出成功!");
                window.location.href = Feng.ctxPath + "/";
            }, function (data) {
                layer.msg("退出失败！" + data.message, {icon: 5, anim: 6});
            });
            request.start();
        });
        wsInst = ws.render({
            wsUrl: Feng.wsUrl, //WebSocket的地址
            connectErr: function (event) {
                console.log(event)
                //如果不支持websocket 回调
            },
            onWsError: function (event) {
                //发生连接错误回调
            },
            onWsOpen: function (event) {
                //连接成功回调
                console.log("Socket 已打开");
                wsInst.send("消息发送测试(From Client)");
            },
            onWsMessage: function (event) {
                //服务器发送消息回调
                let data = event.data;
                try {
                    let msg = JSON.parse(data)
                    notice.info({
                        title: '[' + msg.businessTypeValue + ']' + msg.messageTitle,
                        message: msg.messageContent,
                        timeout: false
                    });
                    $('#messageDot').show();
                } catch (e) {
                }
            },
            onWsClose: function (event) {
                //关闭连接回调
            },

            wsSend: function (event) {
                //发送成功后的回调
            },

        })
    });

    window.unload = function () {
        if (wsInst) {
            wsInst.close();
        }
    };
</script>
</body>

</html>
